package com.slipper.system.flow.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.slipper.system.flow.bo.FlowOpinionBO;
import com.slipper.system.flow.service.FlowOpinionService;
import com.slipper.constants.Constants;
import com.slipper.util.ResultUtil;

/**
 * 流程个人意见表
 */
@RestController
@RequestMapping("/system/flowOpinion")
public class FlowOpinionController {
    @Resource
    private FlowOpinionService flowOpnionService;
    
    @PostMapping(value = "/queryBy")
    public String queryBy(@RequestBody FlowOpinionBO bo) {
        if(bo.getId() == null || "".equals(bo.getId())) {
            return ResultUtil.failureResult("数据获取失败！");
        }
        return ResultUtil.successResult(flowOpnionService.queryBy(bo.getId()));
    }

    @PostMapping(value = "/queryPage")
    public String queryPage(@RequestBody FlowOpinionBO bo) {
        bo.setOwnerId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.successResult(flowOpnionService.queryPage(bo));
    }

    @PostMapping(value = "/save")
    public String save(@RequestBody FlowOpinionBO bo) {
        String employeeId = Constants.getCurrentUser().getEmployeeId();
        bo.setOwnerId(employeeId);
        bo.setUpdateId(employeeId);
        bo.setCreateId(employeeId);
        return ResultUtil.successResult(flowOpnionService.save(bo));
    }

    @PostMapping(value = "/updateByOwner")
    public String updateByOwner(@RequestBody FlowOpinionBO bo) {
        String employeeId = Constants.getCurrentUser().getEmployeeId();
        bo.setOwnerId(employeeId);
        bo.setUpdateId(employeeId);
        bo.setCreateId(employeeId);
        return ResultUtil.successResult(flowOpnionService.updateByOwner(bo));
    }

    @PostMapping(value = "/delete")
    public String delete(@RequestBody FlowOpinionBO bo) {
        String employeeId = Constants.getCurrentUser().getEmployeeId();
        bo.setOwnerId(employeeId);
        bo.setUpdateId(employeeId);
        bo.setCreateId(employeeId);
        return ResultUtil.successResult(flowOpnionService.delete(bo));
    }
}
